package com.cndw.kungfu.model.goods.domain;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.cndw.kungfu.config.ConstantsConfig;
import com.cndw.kungfu.ext.XmlProcesser;

/**
 * 
 * 装备强化
 * 
 * @author <a href="mailto:whz-work@163.com">汪洪州</a>
 * 
 * @since 1.0 Create on 2011-5-30
 */
public class ModeGoodsUpgrade {
	/**
	 * 强化等级
	 */
	private int level;
	/**
	 * 装备类型
	 */
	private int goodsId;
	/**
	 * 消耗宝石数量
	 */
	private int counts;
	/**
	 * 成功率
	 */
	private int ratio;
	/**
	 * 失败降级
	 */
	private int punish;
	/**
	 * 消耗银两
	 */
	private int asset;

	private static int[] blessing = { 103101, 103102, 103103, 103104, 103105, 103106 };

	private static final Map<Integer, ModeGoodsUpgrade> upgradesMap = new HashMap<Integer, ModeGoodsUpgrade>();

	static {
		load();
	}

	public static synchronized void load() {
		if (upgradesMap.isEmpty()) {
			List<ModeGoodsUpgrade> upgradesList = XmlProcesser.processXml(ModeGoodsUpgrade.class, ConstantsConfig.getLocaleResource()+"goodsUpgrade.xml");
			for (ModeGoodsUpgrade upgrade : upgradesList) {
				upgradesMap.put(upgrade.getLevel(), upgrade);
			}
		}
	}

	public static ModeGoodsUpgrade getByLevel(Integer level) {
		return upgradesMap.get(level);
	}

	public static synchronized void updateConfig() {
		upgradesMap.clear();
		load();
	}

	public int getGoodsId() {
		return goodsId;
	}

	public void setGoodsId(int goodsId) {
		this.goodsId = goodsId;
	}

	public int getRatio() {
		return ratio;
	}

	public void setRatio(int ratio) {
		this.ratio = ratio;
	}

	public int getPunish() {
		return punish;
	}

	public void setPunish(int punish) {
		this.punish = punish;
	}

	public static Map<Integer, ModeGoodsUpgrade> getUpgradesMap() {
		return upgradesMap;
	}

	public void setLevel(int level) {
		this.level = level;
	}

	public int getLevel() {
		return level;
	}

	public int getCounts() {
		return counts;
	}

	public void setCounts(int counts) {
		this.counts = counts;
	}

	public int getAsset() {
		return asset;
	}

	public void setAsset(int asset) {
		this.asset = asset;
	}

	public static int[] getBlessing() {
		return blessing;
	}

	public static void setBlessing(int[] blessing) {
		ModeGoodsUpgrade.blessing = blessing;
	}

	public ModeGoodsUpgrade clone(int luck) {
		ModeGoodsUpgrade upgrade = new ModeGoodsUpgrade();
		upgrade.setAsset(getAsset());
		upgrade.setCounts(getCounts());
		upgrade.setGoodsId(getGoodsId());
		upgrade.setLevel(getLevel());
		upgrade.setPunish(getPunish());
		int ratio = getRatio() + luck;
		upgrade.setRatio(ratio > 100 ? 100 : ratio);
		return upgrade;
	}
}
